#ifndef scenary_sprite_h
#define scenary_sprite_h

#include "Texture.h"
#include "ViewPort.h"

class ScenarySprite
{
public:
	//for scenary object
	ScenarySprite(LPD3DXSPRITE SpriteHandler, Texture *texture, int X, int Y, int Width, int Height)
	{
		_Texture = texture;
		_SpriteHandler = SpriteHandler;
		_X = X;
		_Y = Y;
		_Width = Width;
		_Height = Height;
	}
	~ScenarySprite(){}
	void Render(LPDIRECT3DSURFACE9 Target, int xCenter, int yCenter, int alpha, float xScale, float yScale, ViewPort *viewport)
	{
		RECT sRect;
		sRect.left = _X;
		sRect.top = _Y;
		sRect.right = sRect.left + _Width;
		sRect.bottom = sRect.top + _Height;

		D3DXMATRIX idenMatrix;
		D3DXMatrixIdentity(&idenMatrix);
		idenMatrix._22=-1;
		D3DXVECTOR4 vppos;
		D3DXVECTOR3 temp(-viewport -> getLeft() + xCenter, -viewport->getBottom() + yCenter,(float)0);
		D3DXVec3Transform(&vppos,&temp,&idenMatrix);

		D3DXVECTOR3 position((float)vppos.x - _Width/2, (float)vppos.y - _Height/2, 0);

		
		//Flip left or not
		D3DXMATRIX transform; 
		D3DXMatrixTransformation2D(&transform, 
			&D3DXVECTOR2(temp.x,temp.y), 
			0, 
			&D3DXVECTOR2(xScale, yScale), 
			NULL, 
			0, 
			&D3DXVECTOR2(0,0)); 
		_SpriteHandler->SetTransform(&transform); 

		_SpriteHandler -> Draw(_Texture -> GetImage(), 
			&sRect, 
			NULL, 
			&position, 
			D3DCOLOR_ARGB(alpha,255,255,255)
			);
	}
private:
	LPD3DXSPRITE _SpriteHandler;
	Texture *_Texture;
	int _X, _Y;
	int _Width, _Height;
};

#endif